package com.battle.service.controller.web;

import com.battle.pojo.param.exam.*;
import com.battle.pojo.vo.exam.*;
import com.battle.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * web/考试管理
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/exam/web")
public class ExamWebController {

    private final ExamService service;

    public ExamWebController(ExamService service) {
        this.service = service;
    }


    /**
     * 创建考试管理
     *
     * @param param
     * @return
     */
    @PostMapping("/createExam")
    public ApiResult createExam(@RequestBody @Valid CreateExamParam param) {
        service.createExam(param);
        return ApiResult.ok();
    }


    /**
     * 修改考试管理
     *
     * @param param
     */
    @PutMapping("/editExam")
    public ApiResult editExam(@RequestBody @Valid EditExamParam param) {
        service.editExam(param);
        return ApiResult.ok();
    }

    /**
     * 移除考试管理
     *
     * @param id
     */
    @DeleteMapping("/removeExam")
    public ApiResult removeExam(@RequestParam("id") Long id) {
        service.removeExam(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用考试管理
     *
     * @param id
     */
    @GetMapping("/enabledExam")
    public ApiResult enabledExam(@RequestParam("id") Long id) {
        service.enabledExam(id);
        return ApiResult.ok();
    }

    /**
     * 撤回考试
     *
     * @param id
     */
    @GetMapping("/recallExam")
    public ApiResult recallExam(@RequestParam("id") Long id) {
        service.recallExam(id);
        return ApiResult.ok();
    }

    /**
     * 发布考试
     *
     * @param id
     */
    @GetMapping("/publishExam")
    public ApiResult publishExam(@RequestParam("id") Long id) {
        service.publishExam(id);
        return ApiResult.ok();
    }

    /**
     * 获取考试管理详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getExam")
    public ApiResult<GetExamVo> getExam(@RequestParam("id") Long id) {
        GetExamVo vo = service.getExam(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取考试管理列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getExamList")
    public ApiResult<PageResult<GetExamListVo>> getExamList(@RequestBody GetExamListParam param) {
        PageResult<GetExamListVo> result = service.getExamList(param);
        return ApiResult.ok(result);
    }

    /**
     * 获取指定题目列表
     * @param param
     * @return
     */
    @PostMapping("/getAppointQuestionList")
    public ApiResult< PageResult< AppointQuestionJsonVo>> getAppointQuestionList(@RequestBody GetExamListParam param){
        PageResult< AppointQuestionJsonVo> result = service.getAppointQuestionList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取考试管理下拉列表
     *
     * @return
     */
    @PostMapping("/getExamDownList")
    public ApiResult<List<GetExamDownListVo>> getExamDownList(@RequestBody(required = false) @Valid GetExamDownListParam param) {
        List<GetExamDownListVo> list = service.getExamDownList(param);
        return ApiResult.ok(list);
    }


}

